package com.example.carrierapp.ui.main.dispatch;

import android.content.Context;

import com.example.carrierapp.base.BasePresenter;
import com.example.carrierapp.bean.dispatch.DispatchListBean;
import com.example.carrierapp.net.ApiMiddleHelper;
import com.example.carrierapp.net.listener.DataCallBackListener;
import com.example.carrierapp.util.LogUtil;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.Flowable;

public class DispatchPresenter extends BasePresenter<DispatchContract.View> implements DispatchContract.Presenter {
    private Context mContext;
    public DispatchPresenter(Context context) {
        mContext=context;
    }

    @Override
    public void start() {

    }

    @Override
    public void getDispatchList(String filter, int page) {
        Map<String, String> biddingMap = new HashMap<>();
        biddingMap.put("maxResultCount", "10");
        biddingMap.put("skipCount", page + "");
        biddingMap.put("filter", filter);
        Flowable<JsonObject> flowable = apiStrores.getDispatchList(biddingMap);

        LogUtil.d("getFindGoodsList-" + filter+"-"+page);
        ApiMiddleHelper.getInstance().toNetIo2Main(mContext,flowable, new DataCallBackListener() {

            @Override
            public void onSuccess(String json) {
                LogUtil.d("getFindGoodsList-onSuccess-" + json);

                DispatchListBean bean = new Gson().fromJson(json, new TypeToken<DispatchListBean>() {
                }.getType());
                if (getView() != null) {
                getView().getDispatchListSuccess(bean);

                }
            }

            @Override
            public void onFailure(String msg) {
                LogUtil.d("getFindGoodsList-onFailure-" + msg);
                if (getView() != null) {
                getView().getDispatchListFailde(msg);

                }
            }
        });
    }
}
